package com.module.circle.ui.circleDetails

import android.view.Gravity
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.appcompat.widget.LinearLayoutCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.common.app.data.bean.circle.CirclesRankMyRankingBean
import com.common.base.app.extras.dp2px
import com.common.base.app.extras.load
import com.common.base.app.extras.loadCircle
import com.common.base.app.extras.loadRound
import com.common.base.app.extras.no
import com.common.base.utils.ViewUtils.getDrawable
import com.module.circle.R

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2025/07/24
 *
 * 描述：
 *
 * 修订历史：
 *
 */
open class TaskRankingListItemAdapter :
    BaseQuickAdapter<CirclesRankMyRankingBean, BaseViewHolder>(R.layout.circle_item_circle_task_ranking_list_layout) {

    init {
        addChildClickViewIds(R.id.totalRoot)
    }

    override fun convert(holder: BaseViewHolder, item: CirclesRankMyRankingBean) {
        holder.getView<ImageView>(R.id.picImg).loadRound(item.avatar_url, 100)
        holder.setText(R.id.tvName, item.user_name)

        holder.getView<LinearLayoutCompat>(R.id.hrvMedal).removeAllViews()
        item.badge_list?.forEach {
            it.isNullOrEmpty().no {
                val imageView = ImageView(context).apply {
                    // 设置布局参数
                    layoutParams = LinearLayoutCompat.LayoutParams(dp2px(20), dp2px(20)).apply {
                        rightMargin = dp2px(4)
                        gravity = Gravity.CENTER
                    }
                    scaleType = ImageView.ScaleType.FIT_XY
                }

                imageView.load(it, placeholder = R.mipmap.ic_logo_avatar)
                holder.getView<LinearLayoutCompat>(R.id.hrvMedal).addView(imageView)
            }
        }
        holder.setVisible(R.id.imgSex, item.sex >=0)
        holder.getView<ImageView>(R.id.imgSex).setImageDrawable(when(item.sex){
            0-> getDrawable(R.drawable.circle_circle_sex_female_icon)
            1-> getDrawable(R.drawable.circle_circle_sex_male_icon)
            else-> null
        })
        holder.setText(R.id.tvDays, item.score.toString())

//        holder.setVisible(R.id.tvCommanderMark, item.isMyCreation)

        holder.setText(R.id.tvRanking, (holder.layoutPosition+1).toString())

        holder.setTextColor(R.id.tvRanking, when(holder.layoutPosition){
            0-> R.color.c_994000
            1-> R.color.c_4d6fb2
            2-> R.color.c_995d33
            else -> R.color.text_content
        })

        holder.setBackgroundResource(R.id.tvRanking, when(holder.layoutPosition){
            0->R.drawable.bg_round_ffcc33_100
            1->R.drawable.bg_round_c6d2ec_100
            2->R.drawable.bg_round_f0cdc2_100
            else -> R.drawable.bg_round_f2f2f3_100
        })
    }
}